#!/usr/bin/python3
# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name:         search_indexes
# Description:  索引配置
# Author:       牛泽鹏
# Date:         2019/7/11
# -------------------------------------------------------------------------------
from haystack import indexes
from goods.models import Goods


# 注意格式(模型类名+Index)
class GoodsIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    # 设置索引
    name = indexes.NgramField(model_attr='name')
    desc = indexes.NgramField(model_attr='desc')
    category = indexes.NgramField(model_attr='category')
    brand = indexes.NgramField(model_attr='brand')
    price = indexes.NgramField(model_attr='price')
    commodity_unit = indexes.NgramField(model_attr='commodity_unit')
    main_image = indexes.NgramField(model_attr='main_image')

    def get_model(self):
        return Goods

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(is_delete=False).order_by('-create_time')
